<?php

class NodeController extends CommonController {

	public function __construct() {
		parent::__construct();
	}
	
	public function genAction() {
		$path = realpath(PATH_ROOT . '/../texas/');
		$directories = array('lib', 'model', 'api', 'cmsapi', 'config', 'demo', 'crontab', 'lang');
		$file = PATH_ROOT . '/js/path.json';
		@unlink($file);
		$names = array();
		$this->genJson($path . '/lib', $names);
		$this->genJson($path . '/model', $names);
		$this->genJson($path . '/api', $names);
		$this->genJson($path . '/cmsapi', $names);
		$this->genJson($path . '/config', $names);
		$this->genJson($path . '/demo', $names);
		$this->genJson($path . '/crontab', $names);
		$this->genJson($path . '/lang', $names);
		@file_put_contents($file, json_encode($names));
		$this->jsonSuccess('complete!', $names);
	}

	private function genJson($path, &$names) {
		if (!is_dir($path)) 
			return false;

		$nodes = scandir($path);
		foreach ($nodes as $node) {
			if (in_array($node, array('.', '..', '.svn')))
				continue;
			
			$nodePath = "{$path}/{$node}";
			if (is_dir($nodePath)) {
				$this->genJson($nodePath, $names);
			} else {
				$names[] = str_replace('/mnt/hgfs/wwwroot/texas/', '', $nodePath);
			}
		}
	}
}